<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        
        let arr = [11, 7, 5, 3, 71, 9]
        // for (let i = 0; i < arr.length - 1; i++) {
        //     for (let j = 0; j < arr.length - 1 - i; j++) {
        //         if (arr[j] > arr[j + 1]) {
        //             let temp = arr[j]
        //             arr[j] = arr[j + 1]
        //             arr[j + 1] = temp
        //         }
        //     }
        // }
        // console.log(arr)

        // for (let i = 0; i < arr.length - 1; i++) {
        //     let minIndex = i
        //     for (let j = i + 1; j < arr.length; j++) {
        //         if (arr[minIndex] > arr[j]) {
        //             minIndex = j
        //         }
        //     }
        //     let temp = arr[i]
        //     arr[i] = arr[minIndex]
        //     arr[minIndex] = temp
        // }
        // console.log(arr)

        function fastsort(arr) {
            if (arr.length < 2) {
                return arr
            }
            let left = []
            let right = []
            let potIndex = Math.floor(arr.length / 2)
            let pot = arr.splice(potIndex, 1)[0]
            for (let i = 0; i < arr.length; i++) {
                if (arr[i] < pot) {
                    left.push(arr[i])
                } else {
                    right.push(arr[i])
                }
            }
            return fastsort(left).concat([pot], fastsort(right))

        }
        console.log(fastsort(arr))

    </script>

</body>

</html>